<template>
  <el-dialog v-if="load" :close-on-click-modal="false" title="上传回执" v-model="visible" align-center width="800px" :z-index="2000" @close="handleClose">
    <div class="my-2">
      <VUpload v-model="form.contract_list" title="开票合同" class="mb-3" />
      <VUpload v-model="form.deliver_list" title="送货清单" />
    </div>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" :loading="loadings.submit" @click="submit">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import api from '../api'
import { ElMessage } from 'element-plus'
const load = ref(false)
const visible = ref(false)
let loadings = reactive({})
const form = ref({})

const emit = defineEmits(['close', 'success'])

// 打开弹窗
const open = async (b_id) => {
  if (!load.value) {
    load.value = true
    await 1
  }
  loadings = reactive({})
  visible.value = true
  form.value = { b_id, contract_list: [], deliver_list: [] }
}
// 关闭弹窗
const close = () => {
  visible.value = false
}

const handleClose = () => {
  emit('close')
}
// 提交
const submit = () => {
  loadings.submit = true
  api.upload(form.value).then(res => {
    emit('success')
    close()
  }).finally(() => {
    loadings.submit = false
  })
}

defineExpose({ open })
</script>